import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-09-11
 * Time: 10:37
 */
public class lengthOf_LongestSubstring {
    public int lengthOfLongestSubstring(String s) {
        int len=0;
        int left=0;
        HashMap<Character,Integer> hashMap=new HashMap<>();

        for (int right = 0; right < s.length(); right++) {
            // 进⼊窗⼝
            hashMap.put(s.charAt(right),hashMap.getOrDefault(s.charAt(right),0)+1);

            while (hashMap.get(s.charAt(right))>1){// 判断
                hashMap.put(s.charAt(left),hashMap.get(s.charAt(left))-1);
                left++; // 出窗⼝
            }
            len=Math.max(len,right-left+1);
        }
        return len;
    }
}
